class CommentsController < ApplicationController
	load_and_authorize_resource :through => :profile
	
	def add
	end

	def create
		commentable = Profile.find(params[:profile_id])
		params[:comment][:profile] = current_user.profile
		if commentable.comments.create(params[:comment])
			flash[:notice] = "Successfully create comment."
			redirect_to view_account_url(:id => params[:profile_id])
		else
			render :action => 'new'
		end
	end

	def edit
		@profile = Comment.find(params[:id]).commentable
	end

	def update
		if @comment.update_attributes(params[:comment])
			flash[:notice] = "Successfully updated comment."
			redirect_to view_account_url(:id => params[:profile_id])
		else
			render :action => 'edit'
		end
	end

	def destroy
		@comment.destroy
		flash[:notice] = "Successfully destroyed comment."
		#redirect_to view_account_url(:id => params[:profile_id])
		redirect_to :back
	end
end
